package List_;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * ArrayList和LinkedList实现原理，
 * 并比较性能（操作加入新值100000次，随机删除100个值，比较时间）
 */
public class ListTest4 {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        List arrayList = new ArrayList();
        long start = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            arrayList.add(i);
        }
        for (int i = 0; i < 100; i++) {
            arrayList.remove((int) (Math.random() * 100 + 1));
        }
        long end = System.nanoTime();
        System.out.println("耗时" + (end - start));
        List linkedList = new LinkedList();
        long start2=System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            linkedList.add(i);
        }
        for (int i = 0; i < 100; i++) {
           linkedList.remove((int) (Math.random() * 100 + 1));
        }
        long end2 = System.nanoTime();
        System.out.println("耗时2" + (end2 - start2));
    }
}
